package com.xgst.lib.utils

object UnicodeUtils {
    fun unicodeToUTF_8(src: String): String {
        if (null == src) {
            return ""
        }
        println("src: $src")
        val out = StringBuilder()
        var i = 0
        while (i < src.length) {
            val c = src[i]
            if (i + 6 < src.length && c == '\\' && src[i + 1] == 'u') {
                val hex = src.substring(i + 2, i + 6)
                try {
                    out.append(hex.toInt(16).toChar())
                } catch (nfe: NumberFormatException) {
                    nfe.fillInStackTrace()
                }
                i = i + 6
            } else {
                out.append(src[i])
                ++i
            }
        }
        return out.toString()
    }
}